# -*- coding: utf-8 -*-
# @Author : Yuan
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from apps.goods.models import Brand
from apps.meiduo_admin.serializers.brand import BrandModelSerializer
from apps.meiduo_admin.utils import PageNum


class BrandModelViewSet(ModelViewSet):
    queryset = Brand.objects.all()
    serializer_class = BrandModelSerializer
    pagination_class = PageNum

    # def create(self, request, *args, **kwargs):
    #     logo_data = request.FILES.get('logo')
    #     name = request.data.get('name')
    #     first_letter = request.data.get('first_letter')
    #     from fdfs_client.client import Fdfs_client
    #     f_client = Fdfs_client('utils/fastdfs/client.conf')
    #     res = f_client.upload_by_buffer(logo_data.read())
    #     if res['Status'] != 'Upload successed.':
    #         return Response(status=status.HTTP_403_FORBIDDEN)
    #     logo_url = res['Remote file_id']
    #     brand = Brand.objects.create(name=name, logo=logo_url, first_letter=first_letter)
    #     return Response({
    #         'id': brand.id,
    #         'name': brand.name,
    #         'logo': brand.logo.url,
    #         'first_letter': brand.first_letter,
    #     }, status=status.HTTP_201_CREATED)



